package com.eoner.baselibrary.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import com.eoner.baselibrary.R;

public class CashCommonDialog extends Dialog{
    private String title;
    private String cancel;
    private String confirm;
    private int type;

    public CashCommonDialog(@NonNull Context context, String title, String cancel, String confirm) {
        super(context,R.style.MyDialog);
        this.title = title;
        this.cancel = cancel;
        this.confirm = confirm;
    }

    public CashCommonDialog(@NonNull Context context, String title, String cancel, String confirm, int type) {
        super(context, R.style.MyDialog);
        this.title = title;
        this.cancel = cancel;
        this.confirm = confirm;
        this.type = type;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_cash_common);
        TextView tv_title = findViewById(R.id.tv_title);
        TextView tv_cancel = findViewById(R.id.tv_cancel);
        TextView tv_confirm = findViewById(R.id.tv_confirm);
        View line = findViewById(R.id.line);
        if (type == 1) {
            tv_cancel.setVisibility(View.GONE);
            line.setVisibility(View.GONE);
            tv_confirm.setBackgroundResource(R.drawable.cash_common_dialog_confirm1_bkg);
        }

        tv_title.setText(title);
        tv_cancel.setText(cancel);
        tv_confirm.setText(confirm);

        tv_cancel.setOnClickListener(v->{
            if(onChooseListener!=null){
                onChooseListener.cancel();
            }
        });
        tv_confirm.setOnClickListener(v->{
            if(onChooseListener!=null){
                onChooseListener.confirm();
            }
        });

    }

    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        WindowManager.LayoutParams windowparams = window.getAttributes();
        window.setGravity(Gravity.CENTER);
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(windowparams);
    }

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    private OnChooseListener onChooseListener;

    public interface OnChooseListener{
        void cancel();
        void confirm();
    }
}
